package com.ruoyi.gzmx_tag.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gzmx_tag.domain.Gzmx_tag;
import com.ruoyi.gzmx_tag.service.IGzmx_tagService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gzmx_scdw.domain.Gzmx_scdw;
import com.ruoyi.gzmx_scdw.service.IGzmx_scdwService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采集数据点位Controller
 * 
 * @author ruoyi
 * @date 2022-07-26
 */
@Controller
@RequestMapping("/gzmx_tag/gzmx_tag")
public class Gzmx_tagController extends BaseController
{
    private String prefix = "gzmx_tag/gzmx_tag";

    @Autowired
    private IGzmx_tagService gzmx_tagService;
    
    @Autowired
    private IGzmx_scdwService gzmx_scdwService;

    @RequiresPermissions("gzmx_tag:gzmx_tag:view")
    @GetMapping()
    public String gzmx_tag(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
    	Gzmx_scdw gzmx_scdw=new Gzmx_scdw();
    	mmap.put("gzmx_scdw", gzmx_scdw);
    	return prefix + "/gzmx_tag";
    }

    /**
     * 查询采集数据点位列表
     */
    @RequiresPermissions("gzmx_tag:gzmx_tag:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Gzmx_tag gzmx_tag)
    {
        startPage();
        List<Gzmx_tag> list = gzmx_tagService.selectGzmx_tagList(gzmx_tag);
        return getDataTable(list);
    }

    /**
     * 查询设备
     * @param gzmx_tag
     * @return
     */
    @PostMapping("/dev_name")
    @ResponseBody
    public AjaxResult dev_name(@RequestBody Gzmx_tag gzmx_tag){
        List<Map<String, String>> list = gzmx_tagService.selectGzmxdev_name(gzmx_tag);
        return AjaxResult.success(list);
    }

    /**
     * 导出采集数据点位列表
     */
    @RequiresPermissions("gzmx_tag:gzmx_tag:export")
    @Log(title = "采集数据点位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Gzmx_tag gzmx_tag)
    {
        List<Gzmx_tag> list = gzmx_tagService.selectGzmx_tagList(gzmx_tag);
        ExcelUtil<Gzmx_tag> util = new ExcelUtil<Gzmx_tag>(Gzmx_tag.class);
        return util.exportExcel(list, "采集数据点位数据");
    }

    
    @GetMapping("gzmx_tag/{id}")
    public String gzmx_tag_id(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
    	mmap.put("gzmx_scdw", gzmx_scdwService.selectGzmx_scdwById(id));
    	return prefix + "/gzmx_tag";
    }
    
    
    
    /**
     * 新增采集数据点位
     */
    //@GetMapping("/add")
    @GetMapping(value = { "/add/{id}", "/add/" })
    public String add(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
    	if (StringUtils.isNotNull(id))
        {
        	mmap.put("gzmx_scdw", gzmx_scdwService.selectGzmx_scdwById(id));
            
        }else {
        	
        	Gzmx_scdw gzmx_scdw_a=new Gzmx_scdw();   
        	
        	gzmx_scdw_a.setJb(0L);
         
        	mmap.put("gzmx_scdw", gzmx_scdw_a);
        }
    	return prefix + "/add";
    }

    /**
     * 新增保存采集数据点位
     */
    @RequiresPermissions("gzmx_tag:gzmx_tag:add")
    @Log(title = "采集数据点位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Gzmx_tag gzmx_tag)
    {
        return toAjax(gzmx_tagService.insertGzmx_tag(gzmx_tag));
    }

    /**
     * 修改采集数据点位
     */
    @RequiresPermissions("gzmx_tag:gzmx_tag:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Gzmx_tag gzmx_tag = gzmx_tagService.selectGzmx_tagById(id);
        mmap.put("gzmx_tag", gzmx_tag);
        return prefix + "/edit";
    }

    /**
     * 修改保存采集数据点位
     */
    @RequiresPermissions("gzmx_tag:gzmx_tag:edit")
    @Log(title = "采集数据点位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Gzmx_tag gzmx_tag)
    {
        return toAjax(gzmx_tagService.updateGzmx_tag(gzmx_tag));
    }

    /**
     * 删除采集数据点位
     */
    @RequiresPermissions("gzmx_tag:gzmx_tag:remove")
    @Log(title = "采集数据点位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gzmx_tagService.deleteGzmx_tagByIds(ids));
    }

    /**
     * 查询未绑定场景的点位列表
     * @param gzmx_tag
     * @return
     */
    @GetMapping("/scene-pointlist")
    @ResponseBody
    public AjaxResult  getscenePointList(Gzmx_tag gzmx_tag){
        return  AjaxResult.success(gzmx_tagService.selectSceneGzmx_tagList(gzmx_tag));
    }

    /**
     *
     * @param gzmx_tag
     * @return
     */
    @GetMapping("/workspace-pointlist")
    @ResponseBody
    public AjaxResult  getworspacePointList(Gzmx_tag gzmx_tag){
        return  AjaxResult.success(gzmx_tagService.selectWorkspaceGzmx_tagList(gzmx_tag));
    }


    /**
     * 基础管理 绑定点位选择下拉框
     * @param gzmx_tag
     * @return
     */
    @PostMapping("/point-drop-down-list")
    @ResponseBody
    public AjaxResult  pointDropDownList(Gzmx_tag gzmx_tag){
        return  AjaxResult.success(gzmx_tagService.selectGzmx_tagList(gzmx_tag));
    }

    /**
     * 基础管理 未绑定设备的点位列表
     * @param gzmx_tag
     * @return
     */
    @PostMapping("/unboundDeviceTaglist")
    @ResponseBody
    public AjaxResult  unboundDeviceTaglist(Gzmx_tag gzmx_tag){
        return  AjaxResult.success(gzmx_tagService.unboundDeviceTaglist(gzmx_tag));
    }

}
